﻿using SFA;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pay : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public string getRemoteAddr()
    {
        string UserIPAddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
        if (UserIPAddress == null)
        {
            UserIPAddress = Request.ServerVariables["REMOTE_ADDR"];
        }
        return UserIPAddress;
    }
    public string getSecureCookie(HttpRequest Request)
    {

        HttpCookie secureCookie = Request.Cookies["vsc"];
        if (secureCookie != null)
        {
            return secureCookie.ToString();
        }
        else
        {
            return "";
        }


    }
    protected void paybutton_Click(object sender, EventArgs e)
    {
        PGResponse objPGResponse = new PGResponse();
        CustomerDetails oCustomer = new CustomerDetails();
        SessionDetail oSession = new SessionDetail();
        AirLineTransaction oAirLine = new AirLineTransaction();
        MerchanDise oMerchanDise = new MerchanDise();

        SFA.CardInfo objCardInfo = new SFA.CardInfo();

        SFA.Merchant objMerchant = new SFA.Merchant();

        ShipToAddress objShipToAddress = new ShipToAddress();
        BillToAddress oBillToAddress = new BillToAddress();
        ShipToAddress oShipToAddress = new ShipToAddress();
        MPIData objMPI = new MPIData();
        PGReserveData oPGreservData = new PGReserveData();
        Address oHomeAddress = new Address();
        Address oOfficeAddress = new Address();
        // For getting unique MerchantTxnID 
        // Only for testing purpose. 
        // In actual scenario the merchant has to pass his transactionID
        DateTime oldTime = new DateTime(1970, 01, 01, 00, 00, 00);
        DateTime currentTime = DateTime.Now;
        TimeSpan structTimespan = currentTime - oldTime;
        string lMrtTxnID = ((long)structTimespan.TotalMilliseconds).ToString();

        //Setting Merchant Details
        objMerchant.setMerchantDetails("00002595", "00002595", "00002595", "", lMrtTxnID, "Ord123", "http://localhost:3285/PayResponse.aspx", "POST", "INR", "INV123", "req.Sale", "1550.00", "GMT+05:30", "ASP.NET64", "true", "ASP.NET64", "ASP.NET64", "ASP.NET64");

        // Setting BillToAddress Details
        oBillToAddress.setAddressDetails("CID", "Maha Lakshmi", "Aline 1", "Aline2", "Aline3", "Pune", "MH", "48927489", "IND", "tester@opussoft.com");

        // Setting ShipToAddress Details
        oShipToAddress.setAddressDetails("$23@#|", "<script>", "Add 3", "City", "State", "443543", "IND", "tester@opussoft.com");

        //Setting MPI datails.
        //objMPI.setMPIRequestDetails ("1000","INR10.00","356","2","2 shirts","","","","0","","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, application/x-shockwave-flash, */*","Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");

        // Setting Name home/office Address Details 
        // Order of Parameters =>        AddLine1, AddLine2,      AddLine3,   City,   State ,  Zip,          Country, Email id
        oHomeAddress.setAddressDetails("2Sandeep", "Uttam Corner", "Chinchwad", "Pune", "state", "4385435873", "IND", "test@test.com");

        // Order of Parameters =>        AddLine1, AddLine2,      AddLine3,   City,   State ,  Zip,          Country, Email id
        oOfficeAddress.setAddressDetails("2Opus", "MayFairTowers", "Wakdewadi", "Pune", "state", "4385435873", "IND", "test@test.com");

        // Stting  Customer Details 
        // Order of Parameters =>  First Name,LastName ,Office Address Object,Home Address Object,Mobile No,RegistrationDate, flag for matching bill to address and ship to address 
        oCustomer.setCustomerDetails("Sandeep", "patil", oOfficeAddress, oHomeAddress, "9423203297", "13-06-2007", "Y");

        //Setting Merchant Dise Details 
        // Order of Parameters =>       Item Purchased,Quantity,Brand,ModelNumber,Buyers Name,flag value for matching CardName and BuyerName
        oMerchanDise.setMerchanDiseDetails("Computer", "2", "Intel", "P4", "Sandeep Patil", "Y");

        //Setting  Session Details        
        // Order of Parameters =>     Remote Address, Cookies Value            Browser Country,Browser Local Language,Browser Local Lang Variant,Browser User Agent'
        oSession.setSessionDetails(getRemoteAddr(), getSecureCookie(Request), "", Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"], "", Request.ServerVariables["HTTP_USER_AGENT"]);

        //Settingr AirLine Transaction Details  
        //Order of Parameters =>               Booking Date,FlightDate,Flight   Time,Flight Number,Passenger Name,Number Of Tickets,flag for matching card name and customer name,PNR,sector from,sector to'
        oAirLine.setAirLineTransactionDetails("10-06-2007", "22-06-2007", "13:20", "119", "Sandeep", "1", "Y", "25c", "Pune", "Mumbai");

        SFAClient objSFAClient = new SFAClient("D:\\Axisvation\\AccreditationWorkflowProcess\\IQKS.AWP.Online\\Config\\");


        objPGResponse = objSFAClient.postSSL(objMPI, objMerchant, oBillToAddress, oShipToAddress, oPGreservData, oCustomer, oSession, oAirLine, oMerchanDise);

        if (objPGResponse.RedirectionUrl != "" & objPGResponse.RedirectionUrl != null)
        {
            string strResponseURL = objPGResponse.RedirectionUrl;
            Response.Redirect(strResponseURL);
        }
        else
        {
            Response.Write("Response Code:" + objPGResponse.RespCode);
            Response.Write("Response message:" + objPGResponse.RespMessage);
        }

    }
}